//
//  TLPswChangViewController.m
//  FunnyVideo
//
//  Created by 李鑫 on 15/11/10.
//  Copyright © 2015年 NewEggTech. All rights reserved.
//
#import "AVOSManger.h"
#import "TLPswChangViewController.h"

@implementation TLPswChangViewController


- (IBAction)orignalPsw:(id)sender {
    [self.originalPswTF resignFirstResponder];
    [self.nPswTF becomeFirstResponder];
}

- (IBAction)newPsw:(id)sender {
    [self.nPswTF resignFirstResponder];
    [self.confirmPsw becomeFirstResponder];
}

- (IBAction)confirmPsw:(id)sender {
    [self.confirmPsw resignFirstResponder];
    
    [self checkPswTF:^(BOOL isOk, NSString *log) {
        if(isOk)
        {
            dispatch_async(dispatch_get_main_queue(), ^{
                [TLAlertHelper showHUDWithText:@"请稍等..."];
            });
        [[AVOSManger sharedManger] sendPswChangedAction:self.originalPswTF.text andNewPsw:self.originalPswTF.text completion:^(bool isSucc, NSString *info) {
            dispatch_async(dispatch_get_main_queue(), ^{
            if(isSucc)
            {
                [TLAlertHelper showSuccessHUDWithText:info];
                [self.navigationController popViewControllerAnimated:YES];
            }
            else
            {
                [TLAlertHelper showErrorHUDWithText:info];
            }
            });
        }];
        }
        else
        {
            dispatch_async(dispatch_get_main_queue(), ^{
                [TLAlertHelper showErrorHUDWithText:log];
            });
        }
    }];
}


- (void)checkPswTF:(void(^)(BOOL isOk,NSString *log))completion{
    if(self.confirmPsw.text && self.nPswTF.text)
    {
    if([self.confirmPsw.text isEqualToString:self.nPswTF.text])
        completion(YES,@"修改成功");
    else
        completion(NO,@"两次输入密码不同");
    }
    else
        completion(NO,@"请输入完整");
}

@end
